/**
 * Copyright (C) 2013-2014 the original author or authors.
 */
package com.foreveross.bsl.common.utils.exception;

/**
 * @description
 *
 * @author rening
 * @version v1.0
 *
 * @2013-7-25
 *
 */
public class AppExcType {

	/**
	 * System Error
	 */
	public static final String SYS_TYPE = "1";
	
	/**
	 * Business exceptions
	 */
	public static final String BUS_TYPE = "2";
	
	/**
	 * web layer exceptions
	 */
	public static final String WEB_LAYER = "1";
	
	/**
	 * application exceptions
	 */
	public static final String APP_LAYER = "2";
	
	/**
	 * model exceptions
	 */
	public static final String MOD_LAYER = "3";
	
	/**
	 * infra exceptions
	 */
	public static final String INFRA_LAYER = "4";
	
	
	/**
	 * system model exceptions
	 */
	public static final String SYS_MODUL = "00";
	
	/**
	 * mam model exceptions
	 */
	public static final String MAM_MODUL = "01";
	
	/**
	 * push model exceptions
	 */
	public static final String PUS_MODUL = "02";
	
	/**
	 * comments model exceptions
	 */
	public static final String COM_MODUL = "03";
	
	/**
	 * message model exceptions
	 */
	public static final String MES_MODUL = "04";
	
	/**
	 * System Error
	 */
	public static final String SYSTEM_ERROR_CODE = "0000000";
	
	/**
	 * business exception
	 */
	public static final String BUS_ERROR_CODE = "2000000";
	
	/**
	 * get the error code
	 * @param type the type happend error or exception
	 * @param layer the layer that happend error
	 * @param model the system model code
	 * @param code the error message code
	 * @return
	 */
	public static String getCode(String type, String layer, String model, String code){
		StringBuffer sb = new StringBuffer();
		if(type != null){
			sb.append(type);
		} else {
			sb.append(SYS_TYPE);
		}
		if(layer != null){
			sb.append(layer);
		} else {
			sb.append(INFRA_LAYER);
		}
		if(model != null){
			sb.append(model);
		} else {
			sb.append(SYS_MODUL);
		}
		if(code != null){
			sb.append(code);
		}
		return sb.toString();
	}
	
	/**
	 * get system error
	 * @param layer layer the layer that happend error
	 * @param model model the system model code
	 * @param code the error message code
	 * @return
	 */
	public static String getSysCode(String layer, String model, String code){
		return getCode(null, layer, model, code);
	}
	
	/**
	 * get business error
	 * @param layer layer layer the layer that happend error
	 * @param model model model the system model code
	 * @param code code the error message code
	 * @return
	 */
	public static String getBusCode(String layer, String model, String code){
		return getCode(BUS_TYPE, layer, model, code);
	}
}
